﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Agile_E
{
    public partial class ManagerAddInv : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                Car newCar = new Car();
                if (txtyear.Text == string.Empty) newCar.Year = -1; else newCar.Year = Convert.ToInt32(txtyear.Text);
                newCar.Make = txtmake.Text;
                newCar.Model = txtmodel.Text;
                if (ddlType.SelectedValue == "-1")
                {
                    newCar.VehicleType = string.Empty;
                    newCar.VehicleTypeID = -1;
                }
                else
                {
                    newCar.VehicleType = ddlType.SelectedValue;
                    newCar.VehicleTypeID = Convert.ToInt32(ddlstatus.SelectedIndex);
                }
                newCar.VIN_Number = txtVIN.Text;
                if (txtMileage.Text == string.Empty) newCar.Mileage = 0; else newCar.Mileage = Convert.ToInt32(txtMileage.Text);
                newCar.exColor = txtExt.Text;
                newCar.inColor = txtInt.Text;
                newCar.EngineType = txtEngine.Text;
                newCar.Transmission = txttrmn.Text;
                newCar.fuelType = txtFuel.Text;
                newCar.driveType = txtDriveType.Text;
                if (txthp.Text == string.Empty) newCar.Horsepower = 0; else newCar.Horsepower = Convert.ToInt32(txthp.Text);
                if (txttq.Text == string.Empty) newCar.Torque = 0; else newCar.Torque = Convert.ToInt32(txttq.Text);
                if (txtFEcity.Text == string.Empty) newCar.CityFE = 0; else newCar.CityFE = Convert.ToInt32(txtFEcity.Text);
                if (txtFEhw.Text == string.Empty) newCar.HighwayFE = 0; else newCar.HighwayFE = Convert.ToInt32(txtFEhw.Text);
                if (txtMSRP.Text == string.Empty) newCar.TagPrice = 0.00f; else newCar.TagPrice = (float)(Convert.ToDecimal(txtMSRP.Text));
                if (txtPrice.Text == string.Empty) newCar.LowestSalePrice = 0.00f; else newCar.LowestSalePrice = (float)(Convert.ToDecimal(txtPrice.Text));
                if (ddlConditions.SelectedIndex == 0) newCar.Condition = string.Empty; else newCar.Condition = ddlConditions.SelectedValue;
                if (ddlstatus.SelectedValue == "-1") newCar.Status = -1; else newCar.Status = Convert.ToInt32(ddlstatus.SelectedIndex);
                if (txtDate.Text == string.Empty) newCar.DateReceived = Convert.ToDateTime("1/1/1001"); else newCar.DateReceived = Convert.ToDateTime(txtDate.Text);
                newCar.Features = txtFeatures.Text;
                newCar.Warranty = txtWarranty.Text;

                ((Main)this.Master).clearStatus();
                DatabaseHandler.connect();
                DatabaseHandler.addCar(newCar);
            }
            catch (Exception ex)
            {
                ((Main)this.Master).writeStatus(ex.Message, true);
            }
        }
    }
}
